using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SIOGDE.AccesoDatos.Entidades;
using SIOGDE.Negocios;
using SIOGDE.Negocios.Servicios;
using Didsoft.Mvc.DataModel;
using Didsoft.Mvc.Controller;

namespace SIOGDE.Web.Controllers
{
    public class DestinoAsignadoController : BaseController<DestinoAsignado>
    {
	    #region interface servicios DestinoAsignado

		private IDestinoAsignadoNegociosServicio servicio = BusinessFactory.Current.GetDestinoAsignadoNegocios();

		#endregion
		
		
		#region constructor and overridable

        public DestinoAsignadoController()
        {		    
            base.SetDataModelService(servicio);            
        }
		        

		

		#endregion

		#region	actions

		[HttpGet]
		public override ActionResult Index()
        {
            return RedirectToAction("FilterList");
        }

		#endregion


        [HttpPost]
        public JsonResult JSONPagedListByPersona(int personaId = 0, int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        {
            try
            {
                List<DestinoAsignado> searchedItems = servicio.GetPorPersonaId(personaId);
                var items = searchedItems.Skip(jtStartIndex).Take(jtPageSize).ToList();
                return Json(new { Result = "OK", Records = items, TotalRecordCount = searchedItems.Count() });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "ERROR", Message = ex.Message });
            }
        }


        public ActionResult FormDestinoPersona(string personGuid, string redireccion = "")
        {
            ViewBag.PersonaGuid = personGuid;
            var asignacion = new DestinoAsignado() { 
              UnidadMilitarId = null,
              GradoId = null,
              TipoCargoComandoId = null,
              FechaDesde = DateTime.Now,
              FechaHasta = DateTime.Now,
              FechaAsignacion = DateTime.Now,
              Persona = BusinessFactory.Current.GetPersonaNegocios().GetByGuid(personGuid)              
            };
            
            List<Gestion> gestiones =   BusinessFactory.Current.GetGestionNegocios().ObtenerTodas().OrderBy(p=>p.Codigo).ToList();
                       
            var itemsGestiones = new SelectList(gestiones, "Id", "Nombre");
            ViewBag.Gestiones = itemsGestiones;
            ViewBag.Redireccion = redireccion;
            

            return View(asignacion);
        }

        [HttpPost]
        public ActionResult FormDestinoPersona(DestinoAsignado entidad)
        {
            return View();
        }
    }
}

